﻿@inject ITreeService TreeService
@inject NavigationManager NavigationManager

<div class="navroot">
    <ul class="nav flex-column">
        @if (TreeRoot != null)
        {
            @foreach (var (alias, type) in TreeRoot.Collections)
            {
                if (type == PageType.Collection)
                {
                    <Collections CollectionAlias=@alias />
                }
                else if (type == PageType.Page)
                {
                    <Page PageAlias="@alias" />
                }
            }
        }
    </ul>
</div>

@code {
    TreeRootUI? TreeRoot;

    protected override void OnInitialized()
    {
        NavigationManager.LocationChanged += LocationChanged;

        TreeRoot = TreeService.GetRoot();
    }

    private void LocationChanged(object? sender, LocationChangedEventArgs args)
    {
        StateHasChanged();
    }
}
